package ar.com.solidussource.howmuchmobile.activities.generic;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.LinearLayout;
import ar.com.solidussource.howmuchmobile.R;

/**
 * Created with IntelliJ IDEA.
 * User: FT31270775
 * Date: 06/11/12
 * Time: 11:35
 * To change this template use File | Settings | File Templates.
 */
public abstract class BaseActivity extends Activity {
    protected View mContent;
    private static ProgressDialog progressDialog;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base);

        if (!getIntent().getBooleanExtra("ProgressDialogIsShowing", false)) {
            progressDialog = null;
        } else {
            showProgressDialog();
        }
    }

    public void setContent(View view) {
        mContent = view;
        LinearLayout layout = (LinearLayout) findViewById(R.id.base_linear_layout);
        layout.addView(view);
    }

    //@Override
    //public boolean onCreateOptionsMenu(Menu menu) {
    //    //Alternativa 1
    //    MenuInflater inflater = getMenuInflater();
    //    inflater.inflate(R.menu.menu_base, menu);
    //    return true;
    //}

    public void showProgressDialog() {
//		progressDialog = ProgressDialog.show(this, "", "Cargando...");
//		progressDialog = ProgressDialog.show(this, "", "Cargando...", true, true, this);
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);
        //progressDialog.setOnCancelListener(this);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.setIndeterminate(true);
        progressDialog.setMessage("Cargando...");
        progressDialog.show();


        getIntent().putExtra("ProgressDialogIsShowing", true);
    }

    public void hideProgressDialog() {
        if (progressDialog != null) {
            progressDialog.dismiss();
            progressDialog = null;
        }

        getIntent().putExtra("ProgressDialogIsShowing", false);
    }
}